package com.bigFuWengBackend.entity;

import lombok.Data;

import javax.websocket.Session;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

@Data
public class Room {
    private static final int MAX_CAPACITY = 5;
    public String roomId;
    public List<User> users;
    public Map<String, Item> itemPool;
    public Room(){
        users = new CopyOnWriteArrayList<>();
        itemPool = new ConcurrentHashMap<>();
    }
    public boolean isFull() {
        return users.size() >= MAX_CAPACITY;
    }
    public void broadcastMessage(String message) throws IOException {
        for (User player : users) {
            Session session = player.getSession();
            session.getBasicRemote().sendText(message);
        }
    }
}
